import pprint

from ollama import chat

if __name__ == '__main__':
    url = 'http://localhost:11434/api/generate'
    model = 'huihui_ai/deepseek-r1-abliterated:8b'
    question = '太阳的温度?'
    stream = chat(
        model=model,
        messages=[{'role': 'user', 'content': question}],
        stream=True,
    )
    with open('./content.txt', 'a', encoding='utf-8') as f:
        f.write(question + '\n')
    for chunk in stream:
        content = chunk['message']['content']
        # 去掉<think>标签和去除空行
        content = content.split("<think>")[-1].split("</think>")[-1]
        # 替换*
        content = content.replace('*', '')
        with open('./content.txt', 'a', encoding='utf-8') as f:
            f.write(content)
        print(content, end='', flush=True)
